| Conditions | 4 |
| Paths | 10 |
| Total Lines | 143 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function ($) { |
||
| 134 | var stateBarMenu = function () { |
||
| 135 | |||
| 136 | var ACTIVE_THRESHOLD = 55; |
||
| 137 | |||
| 138 | $.fn.isVisible = function (type) { |
||
| 139 | // Current distance from the top of the page |
||
| 140 | var windowScrollTopView = $(window).scrollTop(); |
||
| 141 | // Current distance from the top of the page, plus the height of the window |
||
| 142 | var windowBottomView = windowScrollTopView + $(window).height(); |
||
| 143 | // Element distance from top |
||
| 144 | var elemTop = $(this).offset().top; |
||
| 145 | // Element distance from top, plus the height of the element |
||
| 146 | if (type == "top") { |
||
| 147 | offset = 50; |
||
| 148 | } else if (type == "button") { |
||
| 149 | offset = 15; |
||
| 150 | } else { |
||
| 151 | offset = +380; |
||
| 152 | } |
||
| 153 | var elemBottom = elemTop + $(this).height() + offset; |
||
| 154 | //console.log("wTop " + windowScrollTopView + " wB " + windowBottomView + " eTop" + elemTop); |
||
| 155 | return ((elemBottom <= windowBottomView) && (elemTop >= windowScrollTopView)); |
||
| 156 | }; |
||
| 157 | |||
| 158 | |||
| 159 | if ($('.state-bar').length == 0) return; |
||
| 160 | var fixBarTop = $('.state-bar').offset().top; |
||
| 161 | var donationSection = $("#donation-amount").offset().top; |
||
| 162 | var donationPaymentSection = $("#donation-payment").offset().top; |
||
| 163 | var donationTypeSection = $("#donation-type").offset().top; |
||
| 164 | |||
| 165 | if ($(window).width() < 1023) { |
||
| 166 | $(window).scroll(function () { |
||
| 167 | var currentScroll = $(window).scrollTop(); |
||
| 168 | if (currentScroll + 70 >= fixBarTop) { |
||
| 169 | $('.state-bar').addClass('active'); |
||
| 170 | $('.fixed-button').addClass('active'); |
||
| 171 | $('.menu-main').addClass('under-bar'); |
||
| 172 | |||
| 173 | if ($('.footer').isVisible('top')) { |
||
| 174 | $('.menu-main').removeClass('under-bar'); |
||
| 175 | } else { |
||
| 176 | $(".state-bar").addClass('active'); |
||
| 177 | $('.menu-main').addClass('under-bar'); |
||
| 178 | } |
||
| 179 | |||
| 180 | if ($('#submit-bottom').isVisible('button')) { |
||
| 181 | $('.fixed-button').removeClass('active'); |
||
| 182 | } else { |
||
| 183 | $('.fixed-button').addClass('active'); |
||
| 184 | } |
||
| 185 | |||
| 186 | } else { |
||
| 187 | $('.state-bar').removeClass('active'); |
||
| 188 | $('.menu-main').removeClass('under-bar'); |
||
| 189 | } |
||
| 190 | if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 191 | $('.state-overview .amount').addClass('enabled'); |
||
| 192 | } else { |
||
| 193 | $('.state-overview .amount').removeClass('enabled'); |
||
| 194 | } |
||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | }); |
||
| 199 | } else { |
||
| 200 | $(window).scroll(function () { |
||
| 201 | var currentScroll = $(window).scrollTop(); |
||
| 202 | if ($('body#donation').length) { |
||
| 203 | var initialTop = 200; |
||
| 204 | } else if ($('body#membership').length) { |
||
| 205 | var initialTop = 650; |
||
| 206 | } |
||
| 207 | |||
| 208 | |||
| 209 | if (currentScroll >= initialTop) { |
||
| 210 | $('.state-overview .wrap-bar').addClass('fixed'); |
||
| 211 | //console.log("wrap bar" + currentScroll); |
||
| 212 | } else { |
||
| 213 | $('.state-overview .wrap-bar').removeClass('fixed'); |
||
| 214 | } |
||
| 215 | |||
| 216 | |||
| 217 | if (($('.state-bar-lateral .wrap-bar').outerHeight() + $('.state-bar-lateral .wrap-bar').offset().top ) > ( $('.form-shadow-wrap').offset().top + $('.form-shadow-wrap').outerHeight() + 150)) { |
||
| 218 | $('.state-bar-lateral').removeClass('active'); |
||
| 219 | } else { |
||
| 220 | $('.state-bar-lateral').addClass('active'); |
||
| 221 | } |
||
| 222 | }); |
||
| 223 | } |
||
| 224 | |||
| 225 | // TODO Include this only on mebership pages |
||
| 226 | if ($("body#membership").length) { |
||
| 227 | var memberTypeSection = $("#membership-type").offset().top; |
||
| 228 | $(window).scroll(function () { |
||
| 229 | var currentScroll = $(window).scrollTop(); |
||
| 230 | var typeMemberElements = $('.state-overview .member-type'); |
||
| 231 | var donatorElements = $('.state-overview .donator-type'); |
||
| 232 | var amountElements = $('.state-overview .amount'); |
||
| 233 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 234 | |||
| 235 | typeMemberElements.removeClass('enabled'); |
||
| 236 | donatorElements.removeClass('enabled'); |
||
| 237 | amountElements.removeClass('enabled'); |
||
| 238 | paymentElemnts.removeClass('enabled'); |
||
| 239 | ACTIVE_THRESHOLD = 60; |
||
| 240 | if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 241 | paymentElemnts.addClass('enabled'); |
||
| 242 | } |
||
| 243 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 244 | amountElements.addClass('enabled'); |
||
| 245 | } |
||
| 246 | else if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 247 | donatorElements.addClass('enabled'); |
||
| 248 | } |
||
| 249 | else if (currentScroll >= memberTypeSection - ACTIVE_THRESHOLD) { |
||
| 250 | typeMemberElements.addClass('enabled'); |
||
| 251 | } |
||
| 252 | }); |
||
| 253 | } else { |
||
| 254 | // TODO include only on donation pages? |
||
| 255 | $(window).scroll(function () { |
||
| 256 | var currentScroll = $(window).scrollTop(); |
||
| 257 | var amountElements = $('.state-overview .amount'); |
||
| 258 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 259 | var donatorElements = $('.state-overview .donator-type'); |
||
| 260 | |||
| 261 | amountElements.removeClass('enabled'); |
||
| 262 | paymentElemnts.removeClass('enabled'); |
||
| 263 | donatorElements.removeClass('enabled'); |
||
| 264 | if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 265 | donatorElements.addClass('enabled'); |
||
| 266 | } |
||
| 267 | else if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 268 | paymentElemnts.addClass('enabled'); |
||
| 269 | } |
||
| 270 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 271 | amountElements.addClass('enabled'); |
||
| 272 | } |
||
| 273 | }); |
||
| 274 | } |
||
| 275 | |||
| 276 | }; |
||
| 277 | |||
| 399 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.